package main

import (
	"fmt"
	"math"
	"strings"
)

func main() {
	var a int32 = 0
	fmt.Printf("a = %d,a对应的二进制 = %s\n", a, BinaryFormat(a))
	var b int32 = 100
	fmt.Printf("b = %d,b对应的二进制 = %s\n", b, BinaryFormat(b))
	var c int32 = -100
	fmt.Printf("c = %d,c对应的二进制 = %s\n", c, BinaryFormat(c))
	var d int32 = 342553435
	fmt.Printf("d = %d,d对应的二进制 = %s\n", d, BinaryFormat(d))
	var e int32 = -455567476
	fmt.Printf("e = %d,e对应的二进制 = %s\n", e, BinaryFormat(e))
}

func BinaryFormat(n int32) string {
	a := uint32(n)
	sb := strings.Builder{}
	c := uint32(math.Pow(2, 31))
	for i := 0; i < 32; i++ {
		if a&c != 0 {
			sb.WriteString("1")
		} else {
			sb.WriteString("0")
		}
		c >>= 1
	}
	return sb.String()
}
